package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.entity.YlyqQuartz;
import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.QueryAutoStopOrOpen;
import com.ylyq.ylxx.model.request.CreatAutoStopOrOpen;
import com.ylyq.ylxx.model.request.DeleteAutoStopOrOpenRequest;
import com.ylyq.ylxx.model.request.QueryAutoStopOrOpenRequest;
import com.ylyq.ylxx.model.request.UpdateAutoStopOrOpen;
import com.ylyq.ylxx.quarz.JobServiceImpl;
import com.ylyq.ylxx.service.IOceanegineAutoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName OceanengineAutoController
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/7/2 16:03
 * @Version 1.0
 */
@RestController
@RequestMapping("/oCeanengine/auto")
@Api(description = "巨量引擎自动启停的相关接口")
public class OceanengineAutoController {
    @Autowired
    private IOceanegineAutoService iOceanegineAutoService;

    @PostMapping("/creatAutoStopOrOpen")
    @ApiOperation(value = "创建一个自动启停规则")
    public ResponseData creatAutoStopOrOpen(@RequestBody CreatAutoStopOrOpen creatAutoStopOrOpen) {
        try {
            return iOceanegineAutoService.creatAutoStopOrOpen(creatAutoStopOrOpen);
        } catch (SchedulerException e) {
            e.printStackTrace();
            return new ResponseData(ResponseData.Result.FAIL);
        }
    }

    @PostMapping("/updateAutoStopOrOpen")
    @ApiOperation(value = "更新一个自动启停规则")
    public ResponseData updateAutoStopOrOpen(@RequestBody UpdateAutoStopOrOpen updateAutoStopOrOpen) {
        try {
            return iOceanegineAutoService.updateAutoStopOrOpen(updateAutoStopOrOpen);
        } catch (SchedulerException e) {
            e.printStackTrace();
            return new ResponseData(ResponseData.Result.FAIL);
        }
    }

    @PostMapping("/queryStopOrOpen")
    @ApiOperation(value = "查询自动启停规则", response = QueryAutoStopOrOpen.class)
    public ResponseData queryStopOrOpen(@RequestBody QueryAutoStopOrOpenRequest queryAutoStopOrOpenRequest) {
        return iOceanegineAutoService.queryStopOrOpen(queryAutoStopOrOpenRequest);
    }

    @PostMapping("/deleteAutoStopOrOpen")
    @ApiOperation(value = "删除一个自动启停规则")
    public ResponseData deleteAutoStopOrOpen(@RequestBody List<DeleteAutoStopOrOpenRequest> deleteAutoStopOrOpenRequest) {
        try {
            for (DeleteAutoStopOrOpenRequest temp : deleteAutoStopOrOpenRequest) {
                iOceanegineAutoService.deleteAutoStopOrOpen(temp);
            }
        } catch (SchedulerException e) {
            e.printStackTrace();
            return new ResponseData(ResponseData.Result.FAIL);
        }
        return new ResponseData(ResponseData.Result.SUCCESS);
    }
}
